import request from '@/request'
import { Record, Template, RequiredWithKey } from '@/types'

type CreateRecordData = RequiredWithKey<Omit<Record, 'id'>, 'content' | 'cover' | 'name' | 'theme_style'>

interface UploadFileResponse {
  fileUrl: string
}

export const getRecordDetial = (id: Record['id']) => {
  return request<Record>({
    url: '/record/' + id,
  })
}

export const getTemplateDetial = (id: Template['id']) => {
  return request<Template>({
    url: '/template/' + id,
  })
}

export const createRecord = (data: CreateRecordData) => {
  return request<Template>({
    method: 'POST',
    url: '/record',
    data
  })
}

export const updataRecord = (id: Record['id'], data: Partial<Omit<Record, 'id'>>) => {
  return request<Record>({
    method: 'PATCH',
    url: '/record/' + id,
    data
  })
}

export const uploadFile = (data: FormData) => {
  return request<UploadFileResponse>({
    method: 'POST',
    url: '/upload/file',
    data
  })
}




